//
//  MYGLikeListViewController.swift
//  MYDoctor
//
//  Created by Denny on 2024/3/18.
//

import UIKit
import JXSegmentedView
import MJRefresh
class MYGLikeListViewController: UIViewController,JXSegmentedListContainerViewListDelegate {
    func listView() -> UIView {
        return self.view
    }
    var dataSource = [MYGTopicCollectionModel]()
    var type = 0
    lazy var tableView: UITableView = {
        let control = UITableView()
        control.rowHeight = 166
        control.separatorStyle = .none
        control.dataSource = self
        control.delegate = self
        control.register(UINib.init(nibName: "MYGLikeListTableViewCell", bundle: nil), forCellReuseIdentifier: "MYGLikeListTableViewCell")
        control.mj_header = MJRefreshNormalHeader(refreshingBlock: {[weak self] in
            self?.refreshData()
        })
       
        return control
    }()

  
    func refreshData() {
        MYGLoading.show()
        DennyNetwork.request(MYGMeAPI.myLikes(param: [
            "type":"\(self.type)",
            "k":"2"]), modelType: [MYGTopicCollectionModel].self) { obj in
                self.dataSource = obj
                MYGLoading.hide()
                self.tableView.reloadData()
                self.tableView.mj_header?.endRefreshing()
            } failed: { code, message in
                MYGLoading.hide()
                self.tableView.mj_header?.endRefreshing()
            }
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        refreshData()
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.addSubview(self.tableView)
        self.tableView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
       
    }


}

extension MYGLikeListViewController: UITableViewDataSource,UITableViewDelegate {
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "MYGLikeListTableViewCell", for: indexPath) as! MYGLikeListTableViewCell
        let model = self.dataSource[indexPath.row]
        cell.likeType = self.type
        cell.bindData(model)
        return cell
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.dataSource.count
    }
    
    
}
